<include file="Public/header"/>
<style>
    body {
        background: #f3f3f4;
    }

    #searchbox {
        position: fixed;
        top: 66px;
        right: 20px;
    }
</style>
<div class="wrapper m-t">
    <form class="col-md-9 form-horizontal form-good" action="{:U('')}" method="post">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <span class="h5 font-bold">查询结果</span>
                        <span class="pull-right">
                            <input type="submit" target-form="form-good" class="ajax-post btn btn-info btn-sm"
                                   value="确认提交"/>
                        </span>

                <div class="clearfix"></div>
            </div>
            <div class="ibox-content">
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>名称</th>
                            <th>规格</th>
                            <th>进价</th>
                            <th>售价</th>
                            <th>条形码</th>
                            <th width="100">数量</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!--商品信息-->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </form>

    <div class="col-md-3" id="searchbox">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5><i class="fa fa-search"></i> 物品查询</h5>
            </div>
            <div class="ibox-content" style="height:300px;">
                <div class="row">
                    <div class="col-lg-2">
                        <div class="input-group" style="width: 300px;">
                            <input placeholder="输入关键词，货号、商品名" name='keywrods' type="text" class="form-control"
                                   id="test">

                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>

                    </div>

                </div>
                <div class="form-group m-t">
                    <input type="button" class="btn btn-primary col-lg-8 col-lg-push-2 search" value="查询"/>
                </div>
            </div>
        </div>
    </div>

</div>
<include file="Public/footer"/>
<script src="__PUBLIC__/Admin/js/plugins/layer/layer.min.js"></script>
<script src="__PUBLIC__/Admin/js/bootstrap-suggest.min.js"></script>
<script>
    function initTest() {
        $("#test").bsSuggest('init', {
            allowNoKeyword: false,
            getDataMethod: 'firstByUrl',
            url: "{:U('Stock/test')}",
            idField: "userId",
            keyField: "userName"
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            console.log('onSetSelectValue: ', keyword, data);
        }).on('onUnsetSelectValue', function () {
            console.log('onUnsetSelectValue');
        });
    }
    initTest()
</script>


<script>
    $(function () {
        $('.search').click(function () {
            var keywords = $("[name='keywrods']").val();
            if (keywords == '') {
                layer.alert('请输入关键词', {offset: '100px'});
                return;
            }
            var data = '';
            $.post("{:U('Stock/search')}", {keywords: keywords}, function (re) {
                if (re.state == 'success') {
                    var info = re.info;
                    data += ' <tr>';
                    data += '    <td>' + info.m_number + '</td>';
                    data += '    <td>' + info.m_name + '</td>';
                    data += '    <td>' + info.standard + '</td>';
                    data += '    <td>' + info.bid_price + '</td>';
                    data += '    <td>' + info.sell_price + '</td>';
                    data += '    <td>' + info.bracode + '</td>';
                    data += '    <td><input type="text" class="form-control" value="1" name="counts[]"/></td>';
                    data += '    <td><input type="hidden" name="bracode[]" value="' + info.bracode + '" /><i class="fa fa-times text-danger delete"></i></td>';
                    data += ' </tr>';
                    $('table tbody').append(data);
                } else {
                    layer.alert('没有这个货品');
                    return;
                }
            })


        });
        $("body").on('click', '.delete', function () {
            $(this).parents('tr').remove();
        });
    })
</script>
